/**
 * 初始化调度管理详情对话框
 */
var VehicleScheduleInfoDlg = {
    vehicleScheduleInfoData : {},
    vehicleId : 'VehicleTable',
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    vehicleIds : new Array()
};

/**
 * 清除数据
 */
VehicleScheduleInfoDlg.clearData = function() {
    this.vehicleScheduleInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
VehicleScheduleInfoDlg.set = function(key, val) {
    this.vehicleScheduleInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
VehicleScheduleInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
VehicleScheduleInfoDlg.close = function() {
    parent.layer.close(window.parent.VehicleSchedule.layerIndex);
}

/**
 * 收集数据
 */
VehicleScheduleInfoDlg.collectData = function() {
    this.set('id').set('beginDate').set('goTime').set('endDate').set('interval').set('backTime').set('vehicleIds');
}

/**
 * 提交添加
 */
VehicleScheduleInfoDlg.addSubmit = function() {
	
	  if (this.check()) {
		  this.clearData();
		  this.collectData();
		  debugger
		  //提交信息
		  var ajax = new $ax(Feng.ctxPath + "/vehicleSchedule/add", function(data){
			  Feng.success("添加成功!");
			  window.parent.VehicleSchedule.table.refresh();
			  VehicleScheduleInfoDlg.close();
		  },function(data){
			  Feng.error("添加失败!" + data.responseJSON.message + "!");
		  });
		  ajax.set(this.vehicleScheduleInfoData);
		  ajax.start();
	  }
}

/**
 * 提交修改
 */
VehicleScheduleInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/vehicleSchedule/update", function(data){
        Feng.success("修改成功!");
        window.parent.VehicleSchedule.table.refresh();
        VehicleScheduleInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.vehicleScheduleInfoData);
    ajax.start();
}

/**
 * 检查是否选中
 */
VehicleScheduleInfoDlg.check = function () {
	debugger
	var beginDate = $("#beginDate").val();
	if(beginDate ==""){
		Feng.info("请先选择调度开始日期！");
        return false;
	}
	var endDate = $("#endDate").val();
	if(endDate ==""){
		Feng.info("请先选择调度结束日期！");
        return false;
	}
    var selected = $('#' + this.vehicleId).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中某一车次！");
        return false;
    }else{
    	VehicleScheduleInfoDlg.seItem = selected[0];
    	 for (var i=0; i<selected.length; i++){
    		 VehicleScheduleInfoDlg.vehicleIds[i] = selected[i].id;
         }
    	 $("#vehicleIds").val(JSON.stringify(this.vehicleIds));
        return true;
    }
};


/**
 * 初始化表格的列
 */
VehicleScheduleInfoDlg.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '车辆类型', field: 'vehicleType', visible: false, align: 'center', valign: 'middle', sortable: true},
        {title: '车次', field: 'vehicleNo', align: 'center', valign: 'middle', sortable: true},
        {title: '发车时刻', field: 'departTime', align: 'center', valign: 'middle', sortable: true},
        {title: '到达时刻', field: 'arrTime', align: 'center', valign: 'middle', sortable: true},
        {title: '始发站', field: 'departure', align: 'center', valign: 'middle', sortable: true},
        {title: '终点站', field: 'terminus', align: 'center', valign: 'middle', sortable: true},
        {title: '耗时(分钟)', field: 'costTime', align: 'center', valign: 'middle', sortable: true}
    ];
};
$(function() {
	debugger
	var defaultColunms = VehicleScheduleInfoDlg.initColumn();
    var table = new BSTable(VehicleScheduleInfoDlg.vehicleId, "/vehicle/list", defaultColunms);
    table.setPaginationType("client");
    VehicleScheduleInfoDlg.table = table.init();
});
